1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.connector.impl;
24
25 import java.io.PrintWriter;
26 import java.text.SimpleDateFormat;
27 import java.util.Date;
28
29 import de.bea.domingo.DNotesMonitor;
30 import de.bea.domingo.monitor.AbstractDefaultMonitor;
31
32 /***
33 * @author <a href=mailto:kurt.riede@bea.de>Kurt Riede</a>
34 */
35 public final class DomingoLogAdapter extends AbstractDefaultMonitor implements DNotesMonitor {
36
37 private PrintWriter writer;
38
39 /*** Date format used to format dates in log output. */
40 private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
41
42 /***
43 * Constructor.
44 */
45 public DomingoLogAdapter() {
46 super();
47 }
48
49 /***
50 * Constructor.
51 *
52 * @param theLevel the log level
53 */
54 public DomingoLogAdapter(final int theLevel) {
55 super(theLevel);
56 }
57
58 /***
59 * Sets a new writer to be used by this monitor.
60 *
61 * @param theWriter the new print writer
62 */
63 public void setWriter(final PrintWriter theWriter) {
64 writer = theWriter;
65 }
66
67 /***
68 * Returns the current writer of the monitor.
69 *
70 * @return the current writer
71 */
72 public PrintWriter getWriter() {
73 return writer;
74 }
75
76 /***
77 * {@inheritDoc}
78 *
79 * @see de.bea.domingo.monitor.AbstractDefaultMonitor#monitor(java.lang.String)
80 */
81 protected void monitor(final String message) {
82 final StringBuffer buffer = new StringBuffer();
83 buffer.append("[" + dateFormat.format(new Date()) + "] ");
84 buffer.append(Thread.currentThread().getName() + ": " + message);
85 writer.println(buffer.toString());
86 writer.flush();
87 }
88
89 /***
90 * {@inheritDoc}
91 *
92 * @see de.bea.domingo.monitor.AbstractDefaultMonitor#monitor(java.lang.Throwable)
93 */
94 protected void monitor(final Throwable throwable) {
95 if (throwable != null) {
96 throwable.printStackTrace(writer);
97 }
98 }
99 }